<!DOCTYPE html>
<html lang="zh-CN">
    <head>
  <!-- 元数据 -->
  <meta charset="utf-8">
  <link rel="icon" href="/blog/images/logo.png">
  
  <title>【Java 8 新特性】时间类：ZoneId 和 ZoneOffset | 溪岚花的博客</title>
  
  <meta name="author" content="林家隆" />
  <meta http-equiv="Cache-Control" content="no-transform" />
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="robots" content="index,follow" />
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <meta name="format-detection" content="telphone=no, email=no" />
  
    <meta name="keywords" content="Java" />
  
  <meta name="description" content="本章介绍 java.time 包下两个跟时差相关的类： ZoneId 和 ZoneOffset。 ZoneId：ZoneId 是一个抽象类，它有两个实现类，其中 ZoneRegion 用于表示时区，ZoneOffset 用于表示跟 UTC 时区的偏移量，ZoneId 提供了创建这两种对象的静态方法。因为 ZoneRegion 没有对外提供创建 ZoneRegion 对象的方法，只能由 ZoneId">
<meta property="og:type" content="article">
<meta property="og:title" content="【Java 8 新特性】时间类：ZoneId 和 ZoneOffset">
<meta property="og:url" content="https://lin316.gitee.io/blog/2023/05/11/Java8/time/ZoneId_ZoneOffset/index.html">
<meta property="og:site_name" content="溪岚花的博客">
<meta property="og:description" content="本章介绍 java.time 包下两个跟时差相关的类： ZoneId 和 ZoneOffset。 ZoneId：ZoneId 是一个抽象类，它有两个实现类，其中 ZoneRegion 用于表示时区，ZoneOffset 用于表示跟 UTC 时区的偏移量，ZoneId 提供了创建这两种对象的静态方法。因为 ZoneRegion 没有对外提供创建 ZoneRegion 对象的方法，只能由 ZoneId">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://lin316.gitee.io/blog/blog/images/logo.png">
<meta property="article:published_time" content="2023-05-10T16:00:00.000Z">
<meta property="article:modified_time" content="2025-11-20T11:35:22.181Z">
<meta property="article:author" content="林家隆">
<meta property="article:tag" content="Java">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://lin316.gitee.io/blog/blog/images/logo.png">
  
  <!-- 站点验证相关 -->
  
    
    
    
  
  <!-- 样式表文件 -->
  <link rel="stylesheet" id="kratos-css" href="/blog/css/kratosr.min.css" media="all"></script>
  
    <link rel="stylesheet" id="darkmode-css" href="/blog/css/kr-color-dark.min.css" media="(prefers-color-scheme: dark)"></script>
    <script src="/blog/js/kr-dark.min.js"></script>
  
  
    <link rel="stylesheet" id="highlight-css" href="/blog/css/highlight/night-eighties.min.css" media="all"></script>
  
  <link rel="stylesheet" id="fontawe-css" href="/blog/vendors/font-awesome@4.7.0/css/font-awesome.min.css" media="all"></script>
  <link rel="stylesheet" id="nprogress-css" href="/blog/vendors/nprogress@0.2.0/nprogress.css" media="all"></script>
  
  
  
    <link rel="stylesheet" href="/blog/vendors/@fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.css"></script>
  
  <!-- 不得不预先加载的一些JS文件 -->
  <script src="/blog/vendors/jquery@3.6.0/dist/jquery.min.js"></script>
  
  
  <style>
    
    
  </style>
  
<meta name="generator" content="Hexo 6.3.0"></head>


    <body class="custom-background">
        <div id="kratos-wrapper">
    <div id="kratos-page">
        <div id="kratos-header">
            <header id="kratos-desktop-topnav" class="kratos-topnav">
                <div class="container">
                    <div class="nav-header">
                        <nav id="kratos-menu-wrap">
                            <ul id="kratos-primary-menu" class="sf-menu">
                                
                                    
                                        <li>
                                            
                                                <a href="/blog/">
                                            
                                                
                                                    <i class="fa fa-home"></i>
                                                
                                                首页
                                            </a>
                                            
                                        </li>
                                    
                                        <li>
                                            
                                                <a href="/blog/archives/">
                                            
                                                
                                                    <i class="fa fa-file"></i>
                                                
                                                归档
                                            </a>
                                            
                                        </li>
                                    
                                        <li>
                                            
                                                <a href="/blog/tags/">
                                            
                                                
                                                    <i class="fa fa-tag"></i>
                                                
                                                标签
                                            </a>
                                            
                                        </li>
                                    
                                        <li>
                                            
                                                <a href="/blog/categories/">
                                            
                                                
                                                    <i class="fa fa-folder"></i>
                                                
                                                目录
                                            </a>
                                            
                                        </li>
                                    
                                        <li>
                                            
                                                <a href="/blog/search/">
                                            
                                                
                                                    <i class="fa fa-search"></i>
                                                
                                                搜索
                                            </a>
                                            
                                        </li>
                                    
                                
                            </ul>
                        </nav>
                    </div>
                </div>
            </header>
            <header id="kratos-mobile-topnav" class="kratos-topnav">
                <div class="container">
                    <div class="color-logo"><a href="/blog/">溪岚花的博客</a></div>
                    <div class="nav-toggle">
                        <a class="kratos-nav-toggle js-kratos-nav-toggle">
                            <i></i>
                        </a>
                    </div>
                </div>
            </header>
        </div>
        <div class="kratos-start kratos-hero-2">
            <!-- <div class="kratos-overlay"></div> -->
            <div class="kratos-cover kratos-cover-2 text-center">
                <div class="desc desc2 animate-box">
                    <a href="/blog/">
                        <h2 style="opacity: 0.2;">溪岚花的博客</h2> <br />
                        <span></span>
                    </a>
                </div>
            </div>
        </div>

        <div id="kratos-blog-post">
            <div class="container">
                <div id="main" class="row">
                    

        

            <section class="col-md-8">

        

            <article itemscope itemtype="https://schema.org/Article">
    
    <link itemprop="mainEntityOfPage" href="https://lin316.gitee.io/blog/2023/05/11/Java8/time/ZoneId_ZoneOffset/">
    <div class="kratos-hentry kratos-post-inner clearfix">
        <header class="kratos-entry-header">
            
                <h1 class="kratos-entry-title text-center" itemprop="name headline">【Java 8 新特性】时间类：ZoneId 和 ZoneOffset</h1>
            
            
            <ul class="kratos-post-meta text-center">
                <li><time datetime="2023-05-10T16:00:00.000Z" itemprop="datePublished"><i class="fa fa-calendar"></i> 2023-05-11</time></li>
                <li itemprop="author" itemscope itemtype="https://schema.org/Person">
                    <i class="fa fa-user"></i> 作者 <span itemprop="name">林家隆</span>
                </li>
                
                    <li>
                        <i class="fa fa-edit"></i> 
                        
                        
                            7.99K
                        
                        字
                    </li>
                
                
            </ul>
        </header>
        <div class="kratos-post-content">
            
            <div id="expire-alert" class="alert alert-warning hidden" role="alert">
                <div class="icon"><i class="fa fa-warning"></i></div>
                <div class="text"><p>本文最后编辑于 <time datetime="1763638522181"></time> 前，其中的内容可能需要更新。</p></div>
            </div>
            
            
            
                <div class="kratos-post-inner-toc toc-div-class" >
                    <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#ZoneId"><span class="toc-number">1.</span> <span class="toc-text">ZoneId</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%85%AC%E5%85%B1%E5%B8%B8%E9%87%8F"><span class="toc-number">1.1.</span> <span class="toc-text">公共常量</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%9D%99%E6%80%81%E6%96%B9%E6%B3%95"><span class="toc-number">1.2.</span> <span class="toc-text">静态方法</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#from-TemporalAccessor-temporal"><span class="toc-number">1.2.1.</span> <span class="toc-text">from(TemporalAccessor temporal)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#getAvailableZoneIds"><span class="toc-number">1.2.2.</span> <span class="toc-text">getAvailableZoneIds()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#of-String-zoneId"><span class="toc-number">1.2.3.</span> <span class="toc-text">of(String zoneId)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#of-String-zoneId-Map-lt-String-String-gt-aliasMap"><span class="toc-number">1.2.4.</span> <span class="toc-text">of(String zoneId, Map&lt;String,String&gt; aliasMap)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#ofOffset-String-prefix-ZoneOffset-offset"><span class="toc-number">1.2.5.</span> <span class="toc-text">ofOffset(String prefix, ZoneOffset offset)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#systemDefault"><span class="toc-number">1.2.6.</span> <span class="toc-text">systemDefault()</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%88%90%E5%91%98%E6%96%B9%E6%B3%95"><span class="toc-number">1.3.</span> <span class="toc-text">成员方法</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#getId"><span class="toc-number">1.3.1.</span> <span class="toc-text">getId()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#getRules"><span class="toc-number">1.3.2.</span> <span class="toc-text">getRules()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#normalized"><span class="toc-number">1.3.3.</span> <span class="toc-text">normalized()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%9C%AA%E6%BC%94%E7%A4%BA%E6%96%B9%E6%B3%95"><span class="toc-number">1.3.4.</span> <span class="toc-text">未演示方法</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#ZoneOffset"><span class="toc-number">2.</span> <span class="toc-text">ZoneOffset</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%85%AC%E5%85%B1%E5%B8%B8%E9%87%8F-1"><span class="toc-number">2.1.</span> <span class="toc-text">公共常量</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%9D%99%E6%80%81%E6%96%B9%E6%B3%95-1"><span class="toc-number">2.2.</span> <span class="toc-text">静态方法</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#from-TemporalAccessor-temporal-1"><span class="toc-number">2.2.1.</span> <span class="toc-text">from(TemporalAccessor temporal)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#of-String-offsetId"><span class="toc-number">2.2.2.</span> <span class="toc-text">of(String offsetId)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#ofHours-int-hours"><span class="toc-number">2.2.3.</span> <span class="toc-text">ofHours(int hours)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#ofHoursMinutes-int-hours-int-minutes"><span class="toc-number">2.2.4.</span> <span class="toc-text">ofHoursMinutes(int hours, int minutes)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#ofHoursMinutesSeconds-int-hours-int-minutes-int-seconds"><span class="toc-number">2.2.5.</span> <span class="toc-text">ofHoursMinutesSeconds(int hours, int minutes, int seconds)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#ofTotalSeconds-int-totalSeconds"><span class="toc-number">2.2.6.</span> <span class="toc-text">ofTotalSeconds(int totalSeconds)</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%88%90%E5%91%98%E6%96%B9%E6%B3%95-1"><span class="toc-number">2.3.</span> <span class="toc-text">成员方法</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#getId-1"><span class="toc-number">2.3.1.</span> <span class="toc-text">getId()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#getRules-1"><span class="toc-number">2.3.2.</span> <span class="toc-text">getRules()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#getTotalSeconds"><span class="toc-number">2.3.3.</span> <span class="toc-text">getTotalSeconds()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%9C%AA%E6%BC%94%E7%A4%BA%E6%96%B9%E6%B3%95-1"><span class="toc-number">2.3.4.</span> <span class="toc-text">未演示方法</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%8F%82%E8%80%83%E6%96%87%E7%8C%AE"><span class="toc-number">3.</span> <span class="toc-text">参考文献</span></a></li></ol>
                </div>
            
            <hr />
            <div itemprop="articleBody"><p>本章介绍 <code>java.time</code> 包下两个跟时差相关的类： <code>ZoneId</code> 和 <code>ZoneOffset</code>。</p>
<p><code>ZoneId</code>：<code>ZoneId</code> 是一个抽象类，它有两个实现类，其中 <code>ZoneRegion</code> 用于表示时区，<code>ZoneOffset</code> 用于表示跟 <code>UTC</code> 时区的偏移量，<code>ZoneId</code> 提供了创建这两种对象的静态方法。因为 <code>ZoneRegion</code> 没有对外提供创建 <code>ZoneRegion</code> 对象的方法，只能由 <code>ZoneId</code> 的静态方法创建，并且没有扩展其它方法，因此本章不做介绍。</p>
<p><code>ZoneOffset</code>：用来表示跟 <code>UTC</code> 时区的偏移量。</p>
<h2 id="ZoneId"><a href="#ZoneId" class="headerlink" title="ZoneId"></a>ZoneId</h2><p>在 <code>Java 8</code> 中，跟时区相关的操作通常涉及到 <code>ZoneId</code> 。<code>ZoneId</code> 用来表示时区或偏移量，它用于将时间与时差（以 <code>UTC</code> 为基准）联系起来，以便于表示和计算。在 <code>Java</code> 中，时区都以标准的区域 <code>ID</code> 字符串表示，如  <code>Asia/Shanghai</code> 或 <code>America/New_York</code> 等。</p>
<h3 id="公共常量"><a href="#公共常量" class="headerlink" title="公共常量"></a>公共常量</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* SHORT_IDS：是一个map集合，为我们提供了常用的时区的名称以及对应的简称。</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test01</span><span class="params">()</span>&#123;</span><br><span class="line">    Map&lt;String, String&gt; shortIds = ZoneId.SHORT_IDS;</span><br><span class="line">    <span class="keyword">for</span> (Map.Entry&lt;String, String&gt; zone : shortIds.entrySet()) &#123;</span><br><span class="line">        System.out.println(zone.getKey()+<span class="string">&quot;:&quot;</span>+zone.getValue());</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// NST:Pacific/Auckland</span></span><br><span class="line">    <span class="comment">// HST:-10:00</span></span><br><span class="line">    <span class="comment">// ACT:Australia/Darwin</span></span><br><span class="line">    <span class="comment">// BST:Asia/Dhaka</span></span><br><span class="line">    <span class="comment">// AET:Australia/Sydney</span></span><br><span class="line">    <span class="comment">// IST:Asia/Kolkata</span></span><br><span class="line">    <span class="comment">// CST:America/Chicago</span></span><br><span class="line">    <span class="comment">// NET:Asia/Yerevan</span></span><br><span class="line">    <span class="comment">// AGT:America/Argentina/Buenos_Aires</span></span><br><span class="line">    <span class="comment">// CAT:Africa/Harare</span></span><br><span class="line">    <span class="comment">// MIT:Pacific/Apia</span></span><br><span class="line">    <span class="comment">// BET:America/Sao_Paulo</span></span><br><span class="line">    <span class="comment">// PST:America/Los_Angeles</span></span><br><span class="line">    <span class="comment">// ART:Africa/Cairo</span></span><br><span class="line">    <span class="comment">// JST:Asia/Tokyo</span></span><br><span class="line">    <span class="comment">// VST:Asia/Ho_Chi_Minh</span></span><br><span class="line">    <span class="comment">// IET:America/Indiana/Indianapolis</span></span><br><span class="line">    <span class="comment">// CNT:America/St_Johns</span></span><br><span class="line">    <span class="comment">// PLT:Asia/Karachi</span></span><br><span class="line">    <span class="comment">// PNT:America/Phoenix</span></span><br><span class="line">    <span class="comment">// EST:-05:00</span></span><br><span class="line">    <span class="comment">// EAT:Africa/Addis_Ababa</span></span><br><span class="line">    <span class="comment">// ECT:Europe/Paris</span></span><br><span class="line">    <span class="comment">// PRT:America/Puerto_Rico</span></span><br><span class="line">    <span class="comment">// CTT:Asia/Shanghai</span></span><br><span class="line">    <span class="comment">// SST:Pacific/Guadalcanal</span></span><br><span class="line">    <span class="comment">// MST:-07:00</span></span><br><span class="line">    <span class="comment">// AST:America/Anchorage</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="静态方法"><a href="#静态方法" class="headerlink" title="静态方法"></a>静态方法</h3><h4 id="from-TemporalAccessor-temporal"><a href="#from-TemporalAccessor-temporal" class="headerlink" title="from(TemporalAccessor temporal)"></a>from(TemporalAccessor temporal)</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* from(TemporalAccessor temporal)</span></span><br><span class="line"><span class="comment">* 作用：从其它具有时区或偏移量概念的时间对象中获取zoneId对象。</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test01</span><span class="params">()</span>&#123;</span><br><span class="line">    <span class="type">ZonedDateTime</span> <span class="variable">zonedDateTime01</span> <span class="operator">=</span> ZonedDateTime.now();</span><br><span class="line">    <span class="type">OffsetDateTime</span> <span class="variable">offsetDateTimme01</span> <span class="operator">=</span> OffsetDateTime.now();</span><br><span class="line">    <span class="type">ZoneId</span> <span class="variable">zoneId01</span> <span class="operator">=</span> ZoneId.from(zonedDateTime01);</span><br><span class="line">    <span class="type">ZoneId</span> <span class="variable">zoneId02</span> <span class="operator">=</span> ZoneId.from(offsetDateTimme01);</span><br><span class="line"></span><br><span class="line">    System.out.println(zoneId01); <span class="comment">// 输出 Asia/Shanghai</span></span><br><span class="line">    System.out.println(zoneId02); <span class="comment">// 输出 +08:00</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="getAvailableZoneIds"><a href="#getAvailableZoneIds" class="headerlink" title="getAvailableZoneIds()"></a>getAvailableZoneIds()</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* getAvailableZoneIds()</span></span><br><span class="line"><span class="comment">* 作用：获取所有可用的时区id。</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test02</span><span class="params">()</span>&#123;</span><br><span class="line">    Set&lt;String&gt; zoneIds = ZoneId.getAvailableZoneIds();</span><br><span class="line">    <span class="keyword">for</span> (String zoneId : zoneIds) &#123;</span><br><span class="line">        System.out.println(zoneId);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// Asia/Aden</span></span><br><span class="line">    <span class="comment">// America/Cuiaba</span></span><br><span class="line">    <span class="comment">// Etc/GMT+9</span></span><br><span class="line">    <span class="comment">// Etc/GMT+8</span></span><br><span class="line">    <span class="comment">// Africa/Nairobi</span></span><br><span class="line">    <span class="comment">// ....</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="of-String-zoneId"><a href="#of-String-zoneId" class="headerlink" title="of(String zoneId)"></a>of(String zoneId)</h4><h4 id="of-String-zoneId-Map-lt-String-String-gt-aliasMap"><a href="#of-String-zoneId-Map-lt-String-String-gt-aliasMap" class="headerlink" title="of(String zoneId, Map&lt;String,String&gt; aliasMap)"></a>of(String zoneId, Map&lt;String,String&gt; aliasMap)</h4><h4 id="ofOffset-String-prefix-ZoneOffset-offset"><a href="#ofOffset-String-prefix-ZoneOffset-offset" class="headerlink" title="ofOffset(String prefix, ZoneOffset offset)"></a>ofOffset(String prefix, ZoneOffset offset)</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* of(String zoneId)</span></span><br><span class="line"><span class="comment">* 作用：如果zoneId是时区id，那么创建的是zoneRegion对象。</span></span><br><span class="line"><span class="comment">*      如果是偏移量的格式，那么创建的是zoneOffset对象。</span></span><br><span class="line"><span class="comment">*</span></span><br><span class="line"><span class="comment">* of(String zoneId, Map&lt;String,String&gt; aliasMap)</span></span><br><span class="line"><span class="comment">* 作用：根据时区id创建zoneRegion对象，aliasMap是映射时区id的集合。</span></span><br><span class="line"><span class="comment">*</span></span><br><span class="line"><span class="comment">* ofOffset(String prefix, ZoneOffset offset)</span></span><br><span class="line"><span class="comment">* 作用：获得一个封装偏移量的zoneId对象。如果prefix是GMT、UTC或UT，</span></span><br><span class="line"><span class="comment">*      返回ZoneRegion对象，否则返回ZoneOffset对象。</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test03</span><span class="params">()</span>&#123;</span><br><span class="line">    <span class="type">ZoneId</span> <span class="variable">zoneId01</span> <span class="operator">=</span> ZoneId.of(<span class="string">&quot;Asia/Shanghai&quot;</span>);</span><br><span class="line">    <span class="type">ZoneId</span> <span class="variable">zoneId02</span> <span class="operator">=</span> ZoneId.of(<span class="string">&quot;+08:00&quot;</span>);</span><br><span class="line">    System.out.println(zoneId01.getClass()); <span class="comment">// 输出 class java.time.ZoneRegion</span></span><br><span class="line">    System.out.println(zoneId02.getClass()); <span class="comment">// 输出 class java.time.ZoneOffset</span></span><br><span class="line"></span><br><span class="line">    <span class="type">ZoneId</span> <span class="variable">zoneId03</span> <span class="operator">=</span> ZoneId.of(<span class="string">&quot;CTT&quot;</span>, ZoneId.SHORT_IDS);</span><br><span class="line">    System.out.println(zoneId03.getClass()); <span class="comment">// 输出 class java.time.ZoneRegion</span></span><br><span class="line">    System.out.println(zoneId03);<span class="comment">// 输出 Asia/Shanghai</span></span><br><span class="line"></span><br><span class="line">    <span class="type">ZoneOffset</span> <span class="variable">zoneOffset01</span> <span class="operator">=</span> ZoneOffset.of(<span class="string">&quot;+08:00&quot;</span>);</span><br><span class="line">    <span class="type">ZoneId</span> <span class="variable">zoneId04</span> <span class="operator">=</span> ZoneId.ofOffset(<span class="string">&quot;UTC&quot;</span>, zoneOffset01);</span><br><span class="line">    <span class="type">ZoneId</span> <span class="variable">zoneId05</span> <span class="operator">=</span> ZoneId.ofOffset(<span class="string">&quot;&quot;</span>, zoneOffset01);</span><br><span class="line">    System.out.println(zoneId04.getClass()); <span class="comment">// 输出 class java.time.ZoneRegion</span></span><br><span class="line">    System.out.println(zoneId04); <span class="comment">// 输出 UTC+08:00</span></span><br><span class="line">    System.out.println(zoneId05.getClass()); <span class="comment">// 输出 class java.time.ZoneOffset</span></span><br><span class="line">    System.out.println(zoneId05); <span class="comment">// 输出 +08:00</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="systemDefault"><a href="#systemDefault" class="headerlink" title="systemDefault()"></a>systemDefault()</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* systemDefault()</span></span><br><span class="line"><span class="comment">* 作用：获取操作系统的时区。</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test04</span><span class="params">()</span>&#123;</span><br><span class="line">    System.out.println(ZoneId.systemDefault()); <span class="comment">// 输出 Asia/Shanghai</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="成员方法"><a href="#成员方法" class="headerlink" title="成员方法"></a>成员方法</h3><h4 id="getId"><a href="#getId" class="headerlink" title="getId()"></a>getId()</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* getId()</span></span><br><span class="line"><span class="comment">* 作用：获取时区或偏移量的id。</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test01</span><span class="params">()</span>&#123;</span><br><span class="line">    <span class="type">ZoneId</span> <span class="variable">zoneId01</span> <span class="operator">=</span> ZoneId.of(<span class="string">&quot;Asia/Shanghai&quot;</span>);</span><br><span class="line">    <span class="type">ZoneId</span> <span class="variable">zoneId02</span> <span class="operator">=</span> ZoneId.of(<span class="string">&quot;+08:00&quot;</span>);</span><br><span class="line">    System.out.println(zoneId01.getId()); <span class="comment">// 输出 Asia/Shanghai</span></span><br><span class="line">    System.out.println(zoneId02.getId()); <span class="comment">// 输出 +08:00</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="getRules"><a href="#getRules" class="headerlink" title="getRules()"></a>getRules()</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* getRules()</span></span><br><span class="line"><span class="comment">* 作用：获取时差的计算规则zoneRules对象。</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test02</span><span class="params">()</span>&#123;</span><br><span class="line">    <span class="type">ZoneId</span> <span class="variable">zoneId01</span> <span class="operator">=</span> ZoneId.systemDefault();</span><br><span class="line">    <span class="type">ZoneRules</span> <span class="variable">rules</span> <span class="operator">=</span> zoneId01.getRules();</span><br><span class="line">    System.out.println(rules); <span class="comment">// 输出 ZoneRules[currentStandardOffset=+08:00]</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="normalized"><a href="#normalized" class="headerlink" title="normalized()"></a>normalized()</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* normalized()</span></span><br><span class="line"><span class="comment">* 作用：返回该时区id的标准时区id字符串。如果该时区id已经是标准的时区id字符串，则返回该时区id本身。</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test03</span><span class="params">()</span>&#123;</span><br><span class="line">    <span class="type">ZoneId</span> <span class="variable">zoneId</span> <span class="operator">=</span> ZoneId.of(<span class="string">&quot;UTC&quot;</span>);</span><br><span class="line">    <span class="type">ZoneId</span> <span class="variable">normalizedZoneId</span> <span class="operator">=</span> zoneId.normalized();</span><br><span class="line">    System.out.println(zoneId); <span class="comment">// 输出 UTC</span></span><br><span class="line">    System.out.println(normalizedZoneId); <span class="comment">// 输出 Z</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="未演示方法"><a href="#未演示方法" class="headerlink" title="未演示方法"></a>未演示方法</h4><ol>
<li>equals(Object obj)</li>
<li>getDisplayName(TextStyle style, Locale locale)</li>
<li>hashCode()</li>
<li>toString()</li>
</ol>
<br>

<h2 id="ZoneOffset"><a href="#ZoneOffset" class="headerlink" title="ZoneOffset"></a>ZoneOffset</h2><p><code>ZoneOffset</code> 类表示一个时区偏移量，它表示与 <code>UTC</code> 时间之间的时间差。偏移量的范围为从 <code>UTC-18:00</code> 到 <code>UTC+18:00</code>，以小时为单位。</p>
<h3 id="公共常量-1"><a href="#公共常量-1" class="headerlink" title="公共常量"></a>公共常量</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* MAX：zoneOffset 对象支持的最大偏移量。</span></span><br><span class="line"><span class="comment">* MIN：zoneOffset 对象支持的最小偏移量。</span></span><br><span class="line"><span class="comment">* UTC：偏移量为 0 的 zoneOffset 对象。</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test01</span><span class="params">()</span>&#123;</span><br><span class="line">    System.out.println(ZoneOffset.MAX); <span class="comment">// 输出 zoneOffset对象支持的最大偏移量。</span></span><br><span class="line">    System.out.println(ZoneOffset.MIN); <span class="comment">// 输出 zoneOffset对象支持的最小偏移量。</span></span><br><span class="line">    System.out.println(ZoneOffset.UTC); <span class="comment">// 输出 Z。</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="静态方法-1"><a href="#静态方法-1" class="headerlink" title="静态方法"></a>静态方法</h3><h4 id="from-TemporalAccessor-temporal-1"><a href="#from-TemporalAccessor-temporal-1" class="headerlink" title="from(TemporalAccessor temporal)"></a>from(TemporalAccessor temporal)</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* from(TemporalAccessor temporal)</span></span><br><span class="line"><span class="comment">* 作用：从其他具有时区或偏移量概念的时间对象中获取zoneOffset对象。</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test01</span><span class="params">()</span>&#123;</span><br><span class="line">    <span class="type">ZonedDateTime</span> <span class="variable">zonedDateTime01</span> <span class="operator">=</span> ZonedDateTime.parse(<span class="string">&quot;2007-12-03T10:15:30+08:00[Asia/Shanghai]&quot;</span>);</span><br><span class="line">    <span class="type">ZoneOffset</span> <span class="variable">zoneOffset01</span> <span class="operator">=</span> ZoneOffset.from(zonedDateTime01);</span><br><span class="line">    System.out.println(zoneOffset01); <span class="comment">// 输出 +08:00</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="of-String-offsetId"><a href="#of-String-offsetId" class="headerlink" title="of(String offsetId)"></a>of(String offsetId)</h4><h4 id="ofHours-int-hours"><a href="#ofHours-int-hours" class="headerlink" title="ofHours(int hours)"></a>ofHours(int hours)</h4><h4 id="ofHoursMinutes-int-hours-int-minutes"><a href="#ofHoursMinutes-int-hours-int-minutes" class="headerlink" title="ofHoursMinutes(int hours, int minutes)"></a>ofHoursMinutes(int hours, int minutes)</h4><h4 id="ofHoursMinutesSeconds-int-hours-int-minutes-int-seconds"><a href="#ofHoursMinutesSeconds-int-hours-int-minutes-int-seconds" class="headerlink" title="ofHoursMinutesSeconds(int hours, int minutes, int seconds)"></a>ofHoursMinutesSeconds(int hours, int minutes, int seconds)</h4><h4 id="ofTotalSeconds-int-totalSeconds"><a href="#ofTotalSeconds-int-totalSeconds" class="headerlink" title="ofTotalSeconds(int totalSeconds)"></a>ofTotalSeconds(int totalSeconds)</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* of(String offsetId)</span></span><br><span class="line"><span class="comment">* 作用：将字符串解析成zoneOffset对象，格式如下：</span></span><br><span class="line"><span class="comment">*      +hh:mm:ss</span></span><br><span class="line"><span class="comment">*      -hh:mm:ss</span></span><br><span class="line"><span class="comment">*      ...</span></span><br><span class="line"><span class="comment">*</span></span><br><span class="line"><span class="comment">* ofHours(int hours)</span></span><br><span class="line"><span class="comment">* ofHoursMinutes(int hours, int minutes)</span></span><br><span class="line"><span class="comment">* ofHoursMinutesSeconds(int hours, int minutes, int seconds)</span></span><br><span class="line"><span class="comment">* 作用：给定时分秒数据创建 zoneOffset 对象。</span></span><br><span class="line"><span class="comment">*</span></span><br><span class="line"><span class="comment">* ofTotalSeconds(int totalSeconds)</span></span><br><span class="line"><span class="comment">* 作用：给定距离 00:00:00 的秒数获取 zoneOffset 对象。</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test02</span><span class="params">()</span>&#123;</span><br><span class="line">    <span class="type">ZoneOffset</span> <span class="variable">zoneOffset01</span> <span class="operator">=</span> ZoneOffset.of(<span class="string">&quot;+08:00&quot;</span>);</span><br><span class="line">    System.out.println(zoneOffset01); <span class="comment">// 输出 +08:00</span></span><br><span class="line"></span><br><span class="line">    <span class="type">ZoneOffset</span> <span class="variable">zoneOffset02</span> <span class="operator">=</span> ZoneOffset.ofHours(<span class="number">8</span>);</span><br><span class="line">    <span class="type">ZoneOffset</span> <span class="variable">zoneOffset03</span> <span class="operator">=</span> ZoneOffset.ofHoursMinutesSeconds(<span class="number">8</span>, <span class="number">30</span>, <span class="number">45</span>);</span><br><span class="line">    System.out.println(zoneOffset02); <span class="comment">// 输出 +08:00</span></span><br><span class="line">    System.out.println(zoneOffset03); <span class="comment">// 输出 +08:30:45</span></span><br><span class="line"></span><br><span class="line">    <span class="type">ZoneOffset</span> <span class="variable">zoneOffset04</span> <span class="operator">=</span> ZoneOffset.ofTotalSeconds(<span class="number">1</span>);</span><br><span class="line">    System.out.println(zoneOffset04); <span class="comment">// 输出 +00:00:01</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>


<h3 id="成员方法-1"><a href="#成员方法-1" class="headerlink" title="成员方法"></a>成员方法</h3><h4 id="getId-1"><a href="#getId-1" class="headerlink" title="getId()"></a>getId()</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* getId()</span></span><br><span class="line"><span class="comment">* 作用：获取偏移量 id。</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test01</span><span class="params">()</span>&#123;</span><br><span class="line">    <span class="type">ZoneOffset</span> <span class="variable">zoneOffset01</span> <span class="operator">=</span> ZoneOffset.of(<span class="string">&quot;+08:00&quot;</span>);</span><br><span class="line">    System.out.println(zoneOffset01.getId()); <span class="comment">// 输出 +08:00</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="getRules-1"><a href="#getRules-1" class="headerlink" title="getRules()"></a>getRules()</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* getRules()</span></span><br><span class="line"><span class="comment">* 作用：获取时差的计算规则 zoneRules 对象。</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test02</span><span class="params">()</span>&#123;</span><br><span class="line">    <span class="type">ZoneOffset</span> <span class="variable">zoneOffset01</span> <span class="operator">=</span> ZoneOffset.of(<span class="string">&quot;+08:00&quot;</span>);</span><br><span class="line">    <span class="type">ZoneRules</span> <span class="variable">rules</span> <span class="operator">=</span> zoneOffset01.getRules();</span><br><span class="line">    System.out.println(rules); <span class="comment">// 输出 ZoneRules[currentStandardOffset=+08:00]</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="getTotalSeconds"><a href="#getTotalSeconds" class="headerlink" title="getTotalSeconds()"></a>getTotalSeconds()</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* getTotalSeconds()</span></span><br><span class="line"><span class="comment">* 作用：获取偏移量距离 00:00:00 的秒数</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test03</span><span class="params">()</span>&#123;</span><br><span class="line">    <span class="type">ZoneOffset</span> <span class="variable">zoneOffset01</span> <span class="operator">=</span> ZoneOffset.of(<span class="string">&quot;+00:00:00&quot;</span>);</span><br><span class="line">    <span class="type">ZoneOffset</span> <span class="variable">zoneOffset02</span> <span class="operator">=</span> ZoneOffset.of(<span class="string">&quot;+00:00:01&quot;</span>);</span><br><span class="line">    System.out.println(zoneOffset01.getTotalSeconds()); <span class="comment">// 输出 0</span></span><br><span class="line">    System.out.println(zoneOffset02.getTotalSeconds()); <span class="comment">// 输出 1</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>


<h4 id="未演示方法-1"><a href="#未演示方法-1" class="headerlink" title="未演示方法"></a>未演示方法</h4><ol>
<li>adjustInto(Temporal temporal)</li>
<li>compareTo(ZoneOffset other)getDays()</li>
<li>equals(Object obj)</li>
<li>get(TemporalField field)</li>
<li>getLong(TemporalField field)</li>
<li>hashCode()</li>
<li>isSupported(TemporalField field)</li>
<li>query(TemporalQuery<R> query)</R></li>
<li>range(TemporalField field)</li>
<li>toString()</li>
</ol>
<h2 id="参考文献"><a href="#参考文献" class="headerlink" title="参考文献"></a>参考文献</h2><p><a target="_blank" rel="noopener" href="https://www.matools.com/api/java8">https://www.matools.com/api/java8</a></p>
</div>
        </div>
        
        <footer class="kratos-entry-footer clearfix">
            
            <div class="footer-tag clearfix">
                <div class="pull-left">
                <i class="fa fa-tags"></i>
                    <a class="tag-none-link" href="/blog/tags/Java/" rel="tag">Java</a>
                </div>
                <div class="pull-date">
                    <time datetime="2025-11-20T11:35:22.181Z" itemprop="dateModified">最后编辑：2025-11-20</time>
                </div>
            </div>
        </footer>
    </div>
    
        <nav class="navigation post-navigation clearfix" role="navigation">
            
            <div class="nav-previous clearfix">
                <a title=" Idea 常用快捷键" href="/blog/2023/05/10/Idea/IDEA常用快捷键/">&lt; 上一篇</a>
            </div>
            
            
            <div class="nav-next clearfix">
                <a title=" MySQL 中常用的函数" href="/blog/2023/05/15/mysql/常用函数/">下一篇 &gt;</a>
            </div>
            
        </nav>
    
    
</article>

        

            </section>

        

                
            

<section id="kratos-widget-area" class="col-md-4 hidden-xs hidden-sm">
    <!-- 文章和页面根据splitter来分割，没有的话就从头开始设置为sticky -->
    
    
                <aside id="krw-about" class="widget widget-kratos-about clearfix">
    <div class="photo-background"></div>
    <div class="photo-wrapper clearfix">
        <div class="photo-wrapper-tip text-center">
            <img class="about-photo" src="/blog/images/avatar.webp" loading="lazy" decoding="auto" />
        </div>
    </div>
    <div class="textwidget">
        <p class="text-center">极简主义</p>
    </div>
    <div class="site-meta">
        <a class="meta-item" href="/blog/archives/">
            <span class="title">
                文章
            </span>
            <span class="count">
                72
            </span>
        </a>
        <a class="meta-item" href="/blog/categories/">
            <span class="title">
                分类
            </span>
            <span class="count">
                9
            </span>
        </a>
        <a class="meta-item" href="/blog/tags/">
            <span class="title">
                标签
            </span>
            <span class="count">
                27
            </span>
        </a>
    </div>
</aside>
            
                    <div class="sticky-area">
                
                    <aside id="krw-toc" class="widget widget-kratos-toc clearfix toc-div-class" >
    <div class="photo-background"></div>
    <h4 class="widget-title no-after">
        <i class="fa fa-compass"></i>
        文章目录
        <span class="toc-progress-bar" role="progressbar" aria-label="阅读进度："></span>
    </h4>
    <div class="textwidget">
        <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#ZoneId"><span class="toc-text">ZoneId</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%85%AC%E5%85%B1%E5%B8%B8%E9%87%8F"><span class="toc-text">公共常量</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%9D%99%E6%80%81%E6%96%B9%E6%B3%95"><span class="toc-text">静态方法</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#from-TemporalAccessor-temporal"><span class="toc-text">from(TemporalAccessor temporal)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#getAvailableZoneIds"><span class="toc-text">getAvailableZoneIds()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#of-String-zoneId"><span class="toc-text">of(String zoneId)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#of-String-zoneId-Map-lt-String-String-gt-aliasMap"><span class="toc-text">of(String zoneId, Map&lt;String,String&gt; aliasMap)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#ofOffset-String-prefix-ZoneOffset-offset"><span class="toc-text">ofOffset(String prefix, ZoneOffset offset)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#systemDefault"><span class="toc-text">systemDefault()</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%88%90%E5%91%98%E6%96%B9%E6%B3%95"><span class="toc-text">成员方法</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#getId"><span class="toc-text">getId()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#getRules"><span class="toc-text">getRules()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#normalized"><span class="toc-text">normalized()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%9C%AA%E6%BC%94%E7%A4%BA%E6%96%B9%E6%B3%95"><span class="toc-text">未演示方法</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#ZoneOffset"><span class="toc-text">ZoneOffset</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%85%AC%E5%85%B1%E5%B8%B8%E9%87%8F-1"><span class="toc-text">公共常量</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%9D%99%E6%80%81%E6%96%B9%E6%B3%95-1"><span class="toc-text">静态方法</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#from-TemporalAccessor-temporal-1"><span class="toc-text">from(TemporalAccessor temporal)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#of-String-offsetId"><span class="toc-text">of(String offsetId)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#ofHours-int-hours"><span class="toc-text">ofHours(int hours)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#ofHoursMinutes-int-hours-int-minutes"><span class="toc-text">ofHoursMinutes(int hours, int minutes)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#ofHoursMinutesSeconds-int-hours-int-minutes-int-seconds"><span class="toc-text">ofHoursMinutesSeconds(int hours, int minutes, int seconds)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#ofTotalSeconds-int-totalSeconds"><span class="toc-text">ofTotalSeconds(int totalSeconds)</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%88%90%E5%91%98%E6%96%B9%E6%B3%95-1"><span class="toc-text">成员方法</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#getId-1"><span class="toc-text">getId()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#getRules-1"><span class="toc-text">getRules()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#getTotalSeconds"><span class="toc-text">getTotalSeconds()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%9C%AA%E6%BC%94%E7%A4%BA%E6%96%B9%E6%B3%95-1"><span class="toc-text">未演示方法</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%8F%82%E8%80%83%E6%96%87%E7%8C%AE"><span class="toc-text">参考文献</span></a></li></ol>
    </div>
</aside>
                
                
  <aside id="krw-categories" class="widget widget-kratos-categories clearfix">
    <h4 class="widget-title"><i class="fa fa-folder"></i>分类目录</h4>
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/blog/categories/Docker/">Docker</a><span class="category-list-count">3</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/Idea/">Idea</a><span class="category-list-count">3</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/Java/">Java</a><span class="category-list-count">11</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/Linux/">Linux</a><span class="category-list-count">7</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/MySQL/">MySQL</a><span class="category-list-count">3</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/Python/">Python</a><span class="category-list-count">11</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/Selenium/">Selenium</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/SpringBoot/">SpringBoot</a><span class="category-list-count">4</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/SpringCloud/">SpringCloud</a><span class="category-list-count">13</span></li></ul>
  </aside>


            
                
  <aside id="krw-tags" class="widget widget-kratos-tags clearfix">
    <h4 class="widget-title"><i class="fa fa-tags"></i>标签聚合</h4>
      <div class="tag-clouds">
        <a href="/blog/tags/CORS/" style="font-size: 0.8em;">CORS</a> <a href="/blog/tags/Docker/" style="font-size: 0.8em;">Docker</a> <a href="/blog/tags/Dubbo/" style="font-size: 0.8em;">Dubbo</a> <a href="/blog/tags/ELK/" style="font-size: 0.8em;">ELK</a> <a href="/blog/tags/Elasticsearch/" style="font-size: 0.8em;">Elasticsearch</a> <a href="/blog/tags/Eureka/" style="font-size: 0.8em;">Eureka</a> <a href="/blog/tags/Feign/" style="font-size: 0.8em;">Feign</a> <a href="/blog/tags/Gateway/" style="font-size: 0.8em;">Gateway</a> <a href="/blog/tags/Idea/" style="font-size: 0.8em;">Idea</a> <a href="/blog/tags/Java/" style="font-size: 0.8em;">Java</a> <a href="/blog/tags/JavaWeb/" style="font-size: 0.8em;">JavaWeb</a> <a href="/blog/tags/Linux/" style="font-size: 0.8em;">Linux</a> <a href="/blog/tags/Maven/" style="font-size: 0.8em;">Maven</a> <a href="/blog/tags/MySQL/" style="font-size: 0.8em;">MySQL</a> <a href="/blog/tags/Mybatis/" style="font-size: 0.8em;">Mybatis</a> <a href="/blog/tags/Nacos/" style="font-size: 0.8em;">Nacos</a> <a href="/blog/tags/Pytest/" style="font-size: 0.8em;">Pytest</a> <a href="/blog/tags/Python/" style="font-size: 0.8em;">Python</a>
      </div>
  </aside>

            
                
  <aside id="krw-posts" class="widget widget-kratos-posts">
  <h4 class="widget-title"><i class="fa fa-file"></i>最新文章</h4>
  <div class="tab-content">
      <ul class="list-group">
        
        
          
          
            <a class="list-group-item" href="/blog/2024/04/07/Java%E6%97%A5%E5%BF%97%E6%A1%86%E6%9E%B6/Java%E6%97%A5%E5%BF%97%E6%A1%86%E6%9E%B6/"><i class="fa  fa-book"></i> 【Java】常见的日志框架</a>
            
          
        
          
          
            <a class="list-group-item" href="/blog/2024/04/06/SpringCloud/ElasticStack/Elasticsearch%E6%90%9C%E7%B4%A2%E8%AF%AD%E6%B3%95/"><i class="fa  fa-book"></i> 【ES】搜索语法</a>
            
          
        
          
          
            <a class="list-group-item" href="/blog/2024/04/03/SpringCloud/ElasticStack/Elasticsearch%E7%B4%A2%E5%BC%95%E9%85%8D%E7%BD%AE/"><i class="fa  fa-book"></i> 【ES】索引配置</a>
            
          
        
          
          
            <a class="list-group-item" href="/blog/2024/04/02/SpringCloud/ElasticStack/Kibana%E5%B8%B8%E7%94%A8%E5%8A%9F%E8%83%BD/"><i class="fa  fa-book"></i> 【Kibana】常用功能</a>
            
          
        
          
          
            <a class="list-group-item" href="/blog/2024/04/02/SpringCloud/ElasticStack/IK%E5%88%86%E8%AF%8D%E5%99%A8/"><i class="fa  fa-book"></i> 【IK 分词器】基本使用</a>
            
          
        
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
      </ul>
  </div>
  </aside>

            
    </div>
</section>
        
        </div>
    </div>
</div>
<footer>
    <div id="footer"  >
        <div class="container">
            <div class="row">
                <div class="col-md-6 col-md-offset-3 footer-list text-center">
                    <ul class="kratos-social-icons">
                        <!-- Keep for compatibility -->
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        <!-- New links -->
                        
                    </ul>
                    <ul class="kratos-copyright">
                        <div>
                            <li>&copy; 2025 溪岚花的博客 版权所有.</li>
                            <li>本站已运行<span id="span_dt">Loading...</span></li>
                        </div>
                        <div>
                            <li>Theme <a href="https://github.com/Candinya/Kratos-Rebirth" target="_blank">Kratos:Rebirth</a></li>
                            <li>Site built with&nbsp;<i class="fa fa-heart throb" style="color:#d43f57"></i>&nbsp;by 林家隆.</li>
                        </div>
                        <div>
                            <li>Powered by <a href="https://hexo.io" target="_blank" rel="nofollow">Hexo</a></li>
                            <li>Hosted on <a href="https://gitee.com/" target="_blank">Gitee Pages</a></li>
                        </div>
                        <div>
                            
                            
                        </div>
                    </ul>
                </div>
            </div>
        </div>
        <div class="kr-tool text-center">
            <div class="tool">
                
                    <div class="box search-box">
                        <a href="/blog/search/">
                            <span class="fa fa-search"></span>
                        </a>
                    </div>
                
                
                    <div class="box theme-box" id="darkmode-switch">
                        <span class="fa fa-adjust"></span>
                    </div>
                
                
                
            </div>
            <div class="box gotop-box">
                <span class="fa fa-chevron-up"></span>
            </div>
        </div>
    </div>
</footer>
</div>
</div>

        <script defer src="/blog/vendors/bootstrap@3.3.4/dist/js/bootstrap.min.js"></script>
<script defer src="/blog/vendors/nprogress@0.2.0/nprogress.js"></script>
<script>
    if (!window.kr) {
        window.kr = {};
    }
    window.kr.notMobile = (!(navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i)));
    window.kr.siteRoot = "/blog/";
</script>





    <script defer src="/blog/vendors/@fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.js"></script>

<script defer src="/blog/js/kratosr.min.js"></script>
<script defer src="/blog/js/pjax.min.js"></script>



<!-- Extra support for third-party plguins  -->


    </body>
</html>